<template>
 <view class="main">
    <view class="ohead">
	  <view class="ohead1">
	  <view class="ohead-1">订单信息</view> 
	  <view class="ohead-2">订单号：{{order.ordersn}}</view>
	  </view>
	  <view class="ohead2">
		 <view class="ohead-3">
			<image :src="order.uavatar" class="uimg"></image>
		 </view>
		 <view class="ohead-4">
		 	<view class="ohead-5">{{order.xm}}</view>
			<view class="ohead-6">{{order.total_price}}￥</view>		 
		 </view>
	  </view>
	  
	  
   </view>
   <view class="part1">
	   <view class="oinfo1">
		<image src="https://ppp.new.zeroitem.cn/ppp/conf_1.png" class="img1"></image>
		时间</view>
	   <view class="oinfo2">{{order.sj}}</view>
	   <view class="oinfo2">{{order.pdate}}</view>
	   <view class="oinfo1">
		<image src="https://ppp.new.zeroitem.cn/ppp/conf_2.png" class="img2"></image>   
		地点</view>
	   <view class="oinfo2">{{order.jtdz}}</view>
        <map :latitude="order.lat":longitude="order.lng" class="img3"></map>  
       <view class="oinfo1">
		 <image src="https://ppp.new.zeroitem.cn/ppp/conf_5.png" class="img4"></image> 
		联系人：{{order.xm}}   {{order.phone}} </view>
		
	   <block v-if="order.otype==1"> 
	   <view class="oinfo1 pm1">
	    <image src="https://ppp.new.zeroitem.cn/ppp/conf_3.png" class="img6"></image>
	    ￥ {{order.total_price}}
		</view>
		
	<view class="oinfo1 pm1" v-if="my.user_money>0 || my.user_integral>0">
	 <image src="https://ppp.new.zeroitem.cn/ppp/conf_3.png" class="img6"></image>
	 <switch  @change="switch1Change" style="margin-left:20rpx"></switch>
	  余额代金券抵扣（{{my.user_money}}余额，{{my.user_integral}}小时券）
	</view>		
		
		
		
		
	   <view class="oinfo1">
	   <image src="https://ppp.new.zeroitem.cn/ppp/conf_4.png" class="img5"></image> 
		 备注说明</view>
	   <view class="oinfo2" style="height:auto;">
		 <view class="mmp" v-if="order.slice_type==2">
		  <video :src="video_src" style="width:318rpx;height:162rpx"></video>
		 </view>
	    {{order.remark}}
	   </view> 

		 <view class="car" @click="pay()">
		   <image src="https://ppp.new.zeroitem.cn/ppp/car.png" class="img7"></image>
		   确认并支付 
		 </view>
		</block>		

	   <block v-if="order.otype==3"> 
	   <view class="oinfo1">
	   <image src="https://ppp.new.zeroitem.cn/ppp/conf_4.png" class="img5"></image> 
		 备注说明</view>
	   <view class="oinfo2" style="height:auto;">
		 <view class="mmp" v-if="order.slice_type==2">
		  <video :src="video_src" style="width:318rpx;height:162rpx"></video>
		 </view>
	    {{order.remark}}
	   </view> 
	   <view class="oinfo1 pm1">
		  <image src="https://ppp.new.zeroitem.cn/ppp/conf_3.png" class="img6"></image>
		   悬赏   ￥ {{order.total_price}}</view>
	   <view class="oinfo3">如无人接单将全额退款</view>
		 <view class="car" @click="pay()" v-if="qd==0 && cha==0">
		   <image src="https://ppp.new.zeroitem.cn/ppp/car.png" class="img7"></image>
		   确认悬赏并支付 
		 </view>
		 <view class="car qdbtn" @click="qiangdan()" v-if="qd==1 && cha==0">
		    立即抢单 
		 </view>
		 
		</block>
		
	   <block v-if="order.otype==2"> 
	   <view class="oinfo1 pm1">
	    <image src="https://ppp.new.zeroitem.cn/ppp/conf_3.png" class="img6"></image>
	     ￥ {{order.total_price}}
	   </view>
	   
	<view class="oinfo1 pm1" v-if="my.user_money>0 || my.user_integral>0">
	 <image src="https://ppp.new.zeroitem.cn/ppp/conf_3.png" class="img6"></image>
	 <switch  @change="switch1Change" style="margin-left:20rpx"></switch>
	  余额代金券抵扣（{{my.user_money}}余额，{{my.user_integral}}代金券）
	</view>		   
	   
	   
	   <view class="oinfo1">
	   <image src="https://ppp.new.zeroitem.cn/ppp/conf_4.png" class="img5"></image> 
		 备注说明 【拍同款】</view>
			  <view class="pthp">
				<video :src="yx.vsrc" class="videoc" objectFit="cover"></video> 
				<image src="https://ppp.new.zeroitem.cn/ppp/jja.png" class="jja"></image>
				<view class="face">
				 <image :src="yx.avatar" class="face1"></image>
				 <view class="fname">{{yx.nickname}}</view>	 
				</view>
			  </view>
		 <view class="car" @click="pay()">
		   <image src="https://ppp.new.zeroitem.cn/ppp/car.png" class="img7"></image>
		   确认并支付 
		 </view>
		</block>		
	
   </view>
      
 </view>
</template>

<script>
  import {
		mapGetters,
		mapActions
	} from 'vuex'
	import {
		toLogin
	} from '@/utils/login'
	
	import {
		loadingFun,
		menuJump
	} from '@/utils/tools'	
	
	import {
		loadingType
	} from '@/utils/type'
	
	import {
	   getOrderDetail,yxdetail,orderpay,qdorder,mydetail
	} from '@/api/ppp'	
	const app = getApp()
	export default {
		data() {
		 return {
	      oid:0,
		  order:[],
		  yx:[],
		  video_src:"",
		  qd:0,
		  dkflag:0,
		  my:[],
		  cha:0
		 }
		},
		onLoad(options) {
		  var oid=options.oid;
		  var qd=options.qd;
		  var cha=options.cha;
		  if(qd!=undefined && qd!='' && qd!=0){
			this.qd=1;  
		  }
		  if(cha!=undefined && cha!='' && cha!=0){
		  	 this.cha=1;  
		  }
		  this.oid=oid;
		  this.getDetail();
		  this.getmydetail();
		},
		methods: {
		async getmydetail(){
		  var that=this;
		  const{code,msg,data,
		  }= await mydetail({});
		  if(code==1){
		   that.my=data;
		  }	
		},
		async qiangdan(){
		  var oid=this.oid;
		  const{
		  code,
		  msg,
		  data
		  }= await qdorder({oid:this.oid}); 
		  if(code==1){
	        uni.showToast({title:"抢单成功"})
	        uni.redirectTo({
	        	url:"/pages/ppp/ps/order1?oid="+oid
	        })
		  }
		},	
		async getyxdetail(yid,flag){
			const{
			code,
			msg,
		    data
			}= await yxdetail({id:yid,flag:flag}); 
			if(code==1){
			  this.yx=data;
			}
		 },
		 switch1Change(e){
		  var value=e.target.value;
		  if(value==false){this.dkflag=0;}else{this.dkflag=1;}
		 },
		async pay(){
			const{
			code,
			msg,
		    data
			}= await orderpay({oid:this.oid,dkflag:this.dkflag}); 
			if(code==1){
				if(data.paysuc==1){
				 uni.navigateTo({
				 	url:"/pages/ppp/index/dqdd"
				 })
				 return false;
				}
			 
		                   uni.requestPayment({
									timeStamp: data.timeStamp,
									nonceStr: data.nonceStr,
									package: data.package,
									signType: data.signType,
									paySign: data.paySign,
									// 支付成功的回调
									success(result) {
										if (result.errMsg == "requestPayment:ok") {
											uni.showToast({
												icon: "success",
												title: "购买成功！"
											})
											uni.navigateTo({
												url:"/pages/ppp/index/dqdd"
											})
									 }
		
									},
									// 支付失败回调
									fail(err) {
										uni.showToast({
											icon: "none",
											title: "支付失败"
										})
									}
								})
		 
			   /***
			  if(data.status==1){
				uni.showToast({title:"支付成功"})
				uni.navigateTo({
					url:"/pages/ppp/index/dqdd"
				})
			  }else{
			    uni.showToast({title:data.msg,icon:"none"});  
			  }
			  */
			}
		 },		 
		  async getDetail(){
		    var oid=this.oid;
		    const{
		     code,
			 msg,
			 data
		    }= await getOrderDetail(oid)
			if(code==1){
			 this.order=data;
			 this.video_src='https://ppp-1300934138.cos.ap-shanghai.myqcloud.com/wxFile/'+data.sinfo;
			 if(data.pthid>0){
			  this.getyxdetail(data.pthid,0);
			 }else{
			   this.getyxdetail(data.poid,1); 
			 }
			}
		  },
		}, 
	  }
</script>

<style>
@import "./orderConfire.css";	
</style>
